/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/

#ifndef SIMFRAME_H
#define SIMFRAME_H

#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <wx/menu.h>

#define MENUITEM_OPEN 1000
#define MENUITEM_EXIT 1001
#define MENUITEM_PAUSE 1002
//#define MENUITEM_MODE 1003
#define MENUITEM_REALT 1004
#define MENUITEM_ABOUT 1005

/*
SimCanvas is a opengl canvas with kb-handlers for navigating.
SimFrame is a frame containing simcanvas.
*/

class CWorld;

class CSimCanvas : public wxGLCanvas
{
  DECLARE_EVENT_TABLE()
  public:
    CSimCanvas(wxWindow *ParentWindow, int id, int* attribList);
    ~CSimCanvas();
    
    //event handlers
    void OnKey(wxKeyEvent &e);
    void OnSize(wxSizeEvent &e);
    
    void SetView(); //sets camera viev
    void ResetView(); //reset when resized
  private:
    bool reset;//true if view resetting needed
    float z,y,x, pan,tilt;//camera params
};

class SimFrame : public wxFrame , public wxThread
{
	DECLARE_EVENT_TABLE()
	public:
	 
	
		SimFrame( wxWindow* parent, int id = wxID_ANY, wxString title = _T("FSRSim"),
              wxPoint pos = wxDefaultPosition, wxSize size = wxSize( 577,470 ), 
              int style = wxDEFAULT_FRAME_STYLE/*|wxTAB_TRAVERSAL*/ );
	 
	  ~SimFrame(); 
	   
		//event handlers
		void OnOpen( wxCommandEvent& event );
		void OnExit( wxCommandEvent& event );
		void OnPause( wxCommandEvent& event );
		void OnRealTime( wxCommandEvent& event );
		void OnAbout( wxCommandEvent& event ); 
		void OnContextMenu(wxContextMenuEvent& event);
		void OnClose(wxCloseEvent& event);
		//void OnKey(wxKeyEvent &e);
    //void OnSize(wxSizeEvent &e);
    
    //set opengl view right
    //void SetView();
    
    //thread entry point
    void* Entry();
	
	protected:
		wxStatusBar* StatusBar;
		wxMenuBar* Menubar;
		wxMenu* Menu_File;
		wxMenu* Menu_Simulation;
		wxMenu* Menu_Help;
		
		bool running; //is simulation running
		bool realtime; //realtime mode
		int stepCount;
    int attribList[]; //opengl params for canvas
    CSimCanvas *GLCanvas;
    wxGLContext *GLContext;
    
    CWorld *World;
    
    void init(); //init opengl
	
};

#endif 
